package highscore;

import java.util.Date;

/**
 * Contains all the data from one person in the list.
 *
 * @author Duncan Swedman
 */
public class HighscoreRow
{
    /**
     * Name of the player
     */
    String name;

    /**
     * The level the player was playing when the score was added
     */
    int level;

    /**
     * The score the player had
     */
    int score;

    /**
     * The time when the entry was added (or the one specified when it was added)
     */
    Date date;

    public HighscoreRow(String name, int level, int score, Date date)
    {
		this.name = name;
		this.level = level;
		this.score = score;
		this.date = date;
    }

    public HighscoreRow(String name, int level, int score)
    {
		// When you create a new Date with no arguments it defaults to the current system time
		this(name, level, score, new Date());
    }

    /**
     * Method to set the name of the player.
     * @param name The new name.
     */
    public void setName(String name)
    {
        this.name = name;
    }

    /**
     * Method to get the name of the player
     * @return The name of the player
     */
    public String getName()
    {
        return name;
    }

    /**
     * Method to get the level of the player
     * @return The level of the player
     */
    public int getLevel()
    {
        return level;
    }

    /**
     * Method to get the score of the player
     * @return The name of the score
     */
    public int getScore()
    {
        return score;
    }

    /**
     * Method to get the date this row was created (or the date specified when it was created)
     * @return The date variable of the row
     */
    public Date getDate()
    {
        return date;
    }

    /**
     * Function to compare this row with another object
     * @param obj Check if this row equals another row
     * @return true if they are the same, false othervise
     */
    @Override
    public boolean equals(Object obj)
    {
		if (obj.getClass() != this.getClass())
			return false;

		HighscoreRow row = (HighscoreRow) obj;
		return (row.date == date && row.name.equals(row.name) && row.score == score && row.date.equals(row.date));
    }

    /**
     * Overriden hashCode of the object. Generated by Netbeans
     * @return A haskCode representing the object
     */
    @Override
    public int hashCode()
    {
		int hash = 7;
		hash = 47 * hash + (this.name != null ? this.name.hashCode() : 0);
		hash = 47 * hash + this.level;
		hash = 47 * hash + this.score;
		hash = 47 * hash + (this.date != null ? this.date.hashCode() : 0);
		return hash;
    }

    /**
     * Overwrite toString so we easilly can print the row to the console
     * @return A String containing the Highscore. Note that it is optimized for printing, not for comparing
     */
    @Override
    public String toString()
    {
		return name + "\nScore: " + score + "\nLevel: " + level + "\nTime: " + date.toString();
    }
}
